/**
 *  Config.cpp
 *
 *  Copyright (C) 2008  David Andrs <pda@jasnapaka.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "StdAfx.h"
#include "mLasq.h"
#include "Config.h"
#include "../share/reg.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

#ifdef LOGGING
// logging feature
static LPCTSTR szLogFile = _T("LogFile");
static LPCTSTR szLogLevel = _T("LogLevel");
#endif

// General
static LPCTSTR szUserName = _T("UserName");
static LPCTSTR szPassword = _T("Password");
static LPCTSTR szAutoConnect = _T("AutoConnect");
// GUI
static LPCTSTR szVolume = _T("Volume");

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CConfig Config;

CConfig::CConfig() {
	InstallDir = _T("\\");
	Volume = CONFIG_DEFAULT_VOLUME;
}

CConfig::~CConfig() {
}

BOOL CConfig::Load() {
#ifdef LOGGING
	CRegistry reg(HKEY_CURRENT_USER, REG_KEY_APP);
	LogFile = reg.Read(szLogFile, CONFIG_DEFAULT_LOGFILE);
	LogLevel = reg.Read(szLogLevel, CONFIG_DEFAULT_LOGLEVEL);
//	LogLevel = 7;
#endif

/*	// GUI
	CRegistry regUI(HKEY_CURRENT_USER, REG_KEY_UI);
	ShowOfflineContacts = regUI.Read(szShowOfflineContacts, DEFAULT_SHOW_OFFLINE_CONTACTS);
	ShowTransports = regUI.Read(szShowTransports, DEFAULT_SHOW_TRANSPORTS);
	GlobalStatus = (EStatus) regUI.Read(szStatus, DEFAULT_STATUS);
	if (GlobalStatus < 0 || GlobalStatus > 6)		// 7 types of states
		GlobalStatus = DEFAULT_STATUS;
*/
	// general
	CRegistry regConf(HKEY_CURRENT_USER, REG_KEY_CONFIGURATION);
	UserName = regConf.Read(szUserName, _T(""));
	Password = regConf.Read(szPassword, _T(""));

	AutoConnect = regConf.Read(szAutoConnect, CONFIG_DEFAULT_AUTO_CONNECT);

	// GUI
	Volume = regConf.Read(szVolume, CONFIG_DEFAULT_VOLUME);

	return TRUE;
}

BOOL CConfig::Save() {
/*	// GUI
	CRegistry regUI(HKEY_CURRENT_USER, REG_KEY_UI);
	regUI.Write(szShowOfflineContacts, ShowOfflineContacts);
	regUI.Write(szShowTransports, ShowTransports);
	regUI.Write(szStatus, GlobalStatus);
*/
	// General
	CRegistry regConf(HKEY_CURRENT_USER, REG_KEY_CONFIGURATION);
	regConf.Write(szUserName, UserName);
	regConf.Write(szPassword, Password);

	regConf.Write(szAutoConnect, AutoConnect);

	// GUI
	regConf.Write(szVolume, Volume);

	return TRUE;
}
